package com.hq.base.service;

import com.hq.base.dao.BaseDAO;
import com.hq.base.domain.BaseObject;
import com.hq.common.domain.SearchObject;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by He Zhijie on 2015/8/13.
 */
public abstract class BaseService<T> extends BaseObject{

    public abstract BaseDAO<T> getDao();

    public T get(Serializable id){
        return getDao().get(id);
    }

    /**
     * 表主键为id时才能使用
     * @param ids
     */
    public void delete(List<Serializable> ids){
        getDao().delete(ids);
    }

    public void delete(T instance){
        getDao().delete(instance);
    }

    public List<T> get(Serializable[] ids){
        return getDao().get(ids);
    }

    public List<T> get(T t){
        return getDao().get(t);
    }

    public List<T> get(SearchObject search){
        return getDao().get(search);
    }

    public int getCount(SearchObject search){
        return getDao().getCount(search);
    }

    public List<T> getAll(){
        return getDao().getAll();
    }

    public Serializable save(T instance){
        return getDao().save(instance);
    }

    public void save(List<T> list){
        getDao().save(list);
    }

    public void saveOrUpdate(T instance){
        getDao().saveOrUpdate(instance);
    }

    public void saveOrUpdateAll(List<T> list){
        getDao().saveOrUpdateAll(list);
    }

    public void update(T instance){
        getDao().update(instance);
    }

    public void update(List<T> list){
        getDao().update(list);
    }

    public Map<String,Object> queryWithCount(SearchObject searchObject){
        Map<String,Object> iUserMap=new HashMap<String, Object>(4);
        List<T> list=getDao().get(searchObject);
        iUserMap.put("list", list);
        iUserMap.put("total", getDao().getCount(searchObject));
        return iUserMap;
    }
}
